\insert 'NewPortObject.oz'

declare
fun {MathAgent}
   {NewPortObject 0 
    fun {$ State Msg}
       case Msg of add(N) then
	  State+N
       [] sub(N) then
	  State-N
       [] mult(N) then
	  State*N
       [] divide(N) then
	  State/N
       [] get(N) then
	  State=N
       end
    end
    }		       
end

MathPObj = {MathAgent}
{Send MathPObj add(3)}
{Send MathPObj sub(7)}
{Browse {Send MathPObj get($)}} % displays ~4
{Send MathPObj add(27)}
{Browse {Send MathPObj get($)}} % displays 23
MathPObj2 = {MathAgent}
{Send MathPObj2 mult(27)}
{Browse {Send MathPObj2 get($)}} % displays 0